package org.example.springbootpra1.demos.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.example.springbootpra1.demos.bean.ChargingPile;
import org.example.springbootpra1.demos.bean.ChargingPileWithPlotVO;
import org.example.springbootpra1.demos.services.service.ChargePileWithPlotService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 充电站Controller
 *
 * @author zdcloud
 * @date 2024-09-18
 */
@RestController
@RequestMapping("/pileVo")
public class ChargePileWithPlotController
{
    @Autowired
    private ChargePileWithPlotService chargePileWithPlotService;

//    @GetMapping("/list")
//    public List<ChargingPileWithPlotVO> list()
//    {
//        List<ChargingPileWithPlotVO> list = chargePileWithPlotService.list();
//        return list;
//    }


    @PostMapping("/pageList")
    public IPage<ChargingPileWithPlotVO> pageList()
    {
        IPage<ChargingPileWithPlotVO> list = chargePileWithPlotService.getChargingPileWithPlotPage();
        return list;
    }


    @PostMapping("/queryPageList")
    public IPage<ChargingPileWithPlotVO> pageList(Page<ChargingPileWithPlotVO> page, ChargingPileWithPlotVO chargingPileWithPlotVO)
    {
        QueryWrapper<ChargingPileWithPlotVO> query = Wrappers.query();
        if (chargingPileWithPlotVO.getPkName() != null && !chargingPileWithPlotVO.getPkName().isEmpty()){
            query.like("a.pk_name",chargingPileWithPlotVO.getPkName());
        }
        if (chargingPileWithPlotVO.getId()!=null){
            query.eq("a.id",chargingPileWithPlotVO.getId());
        }

        IPage<ChargingPileWithPlotVO> list = chargePileWithPlotService.getChargingPileWithPlotQueryPage(page, query);
        return list;
    }


}